package com.shopping_assistant.view;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;

public class TestProvider extends Thread {

	private static final String ProviderName = LocationManager.NETWORK_PROVIDER;
	private LocationManager locationManager;
	
	public TestProvider(Context context) {
		
		locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		
		locationManager.addTestProvider(ProviderName, false, false, false, false, false, false, false, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
		locationManager.setTestProviderEnabled(ProviderName, true);
		
	}
	
	@Override
	public void run() {
		
		testIdeal();
		
	}

	private void testIdeal() {
		moveTo(56.171366, 10.190086);

		moveTo(56.171334, 10.190051);

		moveTo(56.171282, 10.190025);

		moveTo(56.171234, 10.189987);

		moveTo(56.171186, 10.189955);

		moveTo(56.171139, 10.189923);

		moveTo(56.171091, 10.18989);
		
	}
	
	private void moveTo(double latitude, double longitude) {
		
		try {
			
			setLocation(latitude, longitude);
		
			Thread.sleep(1000);
			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	private void setLocation(double latitude, double longitude) {
		Location location = new Location(ProviderName);
		
		location.setLatitude(latitude);
		location.setLongitude(longitude);
		location.setTime(System.currentTimeMillis());
		
		locationManager.setTestProviderLocation(ProviderName, location);
	}
}
